package mutipackage;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

public class MServer {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		MServer mainMServer = new MServer() ;
		mainMServer.work();
	}

	private void work() {
		IoAcceptor acceptor = new NioSocketAcceptor();
		acceptor.getFilterChain().addLast("codec",
				new ProtocolCodecFilter(new MutiProtocalCodecFactory(Charset.forName("UTF-8"))));
		acceptor.getSessionConfig().setReadBufferSize(64);
		acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
		acceptor.setHandler(new MutiHandler());
		try {
			acceptor.bind(new InetSocketAddress(ServerConfiguration.PORT));
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println("start server ...");
	}
}
